package org.thirdHero.admin.web;

import org.thirdHero.admin.annotation.LoginAdmin;
import org.thirdHero.core.util.ResponseUtil;
import org.thirdHero.db.domain.SysRelation;
import org.thirdHero.db.domain.SysUser;
import org.thirdHero.db.service.SysRelationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户菜单权限管理
 * */
@RestController
@RequestMapping("/admin/relation")
public class SysRelationController {
    private static final Logger logger = LoggerFactory.getLogger(SysRelationController.class);
    @Resource
    SysRelationService sysRelationService;

    @PostMapping("/savePower/{roleId}")
    @ResponseBody
    public Object savePower(@LoginAdmin SysUser sysUser , @PathVariable Integer roleId, @RequestParam String menuIds){
        this.sysRelationService.saveRelation(roleId,menuIds);
        return ResponseUtil.ok("保存成功");
    }
    @GetMapping("/queryPower/{roleId}")
    @ResponseBody
    public Object queryPower(@LoginAdmin SysUser sysUser , @PathVariable Integer roleId){
        List<SysRelation> sysRelations = this.sysRelationService.queryRelationByRoleId(roleId);
        if(sysRelations ==null || sysRelations.isEmpty()){
            return ResponseUtil.fail(-1,"没有该部门信息");
        }

        ResponseUtil<SysRelation> response = new ResponseUtil<SysRelation>();
        return response.ok("查询成功", sysRelations.size(), sysRelations);
    }


}
